package com.anmai.crawler1.dao;

import com.anmai.crawler1.entity.BussinessBean;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface BussinessDao {

    int deleteByPrimaryKey(Integer id);

    @Insert("insert into bussiness(area_id,bussiness_name,url,create_time,update_time) values(#{areaId},#{bussinessName},#{url},#{createTime},#{updateTime})")
    int insert(BussinessBean record);

    int insertSelective(BussinessBean record);

    BussinessBean selectByPrimaryKey(Integer id);

    int updateByPrimaryKeySelective(BussinessBean record);

    int updateByPrimaryKey(BussinessBean record);

    @Select("select count(id) from bussiness where bussiness_name = #{bussinessName,jdbcType=VARCHAR} and url = #{url,jdbcType=VARCHAR} and area_id = #{areaId,jdbcType=INTEGER}")
    Integer isExist(BussinessBean bussinessBean);

    @Select("select * from bussiness where status = #{status,jdbcType=VARCHAR}")
    @Results({
            @Result(property = "updateTime", column = "update_time"),

            @Result(property = "createTime", column = "create_time"),

            @Result(property = "areaId", column = "area_id"),

            @Result(property = "bussinessName", column = "bussiness_name")

    })
    List<BussinessBean> findErrorBusinesses(@Param("status") Integer status);

    @Update("update bussiness set status =  #{status,jdbcType=INTEGER} where id = #{id,jdbcType=INTEGER}")
    Integer updateStatus(BussinessBean bussinessBean);

    //查找shop中没有爬到的bussiness
    @Select("SELECT id from bussiness b where b.id not in (SELECT DISTINCT bussiness_id FROM shop where bussiness_id <> -10) and status <> 0")
    List<Integer> findNoInShop();



}